package com.weather.service;

import net.sf.json.JSONObject;


public class RequestWeatherDay {
	//public static final String GET_URL = "http://m.weather.com.cn/data/101010100.html";
	//public static final String GET_URL="http://www.weather.com.cn/data/sk/101010100.html";
	//public static final String GET_URL="http://tianqi.cncn.com/beijing";
	//public static final String GET_URL ="http://www.weather.com.cn/data/cityinfo/101010100.html";
	//http://weather.china.com.cn/forecast/2-1-1.html
	public static final String GET_URL="http://weather.51wnl.com/weatherinfo/GetMoreWeather?cityCode=101010100&weatherType=1";
	
	static String lines; 
	 public static JSONObject RequestWeatherOneDay() throws Exception{


			String jsonstr = RequestURL.RequestWeathers(GET_URL);
			JSONObject json = JSONObject.fromObject(jsonstr);
			JSONObject jsonob=JSONObject.fromObject(json.getString("weatherinfo"));
			System.out.println(jsonstr);
			String date = jsonob.getString("time").replaceAll("T", " ");
			String wind = jsonob.getString("WD")+" "+jsonob.getString("WS");
            String sql = "insert into bj_one_day_weather VALUES ("
            		+"'"+date+"'"+","
            		+"'"+jsonob.getString("city")+"'"+","
            		//+"'"+jsonob.getString("WSE")+"'"+","
            		+"'"+wind+"'"+","
            		+"'"+jsonob.getString("temp")+"'"+")";
            WeatherOneDayDBprocess(sql);
            return jsonob;
          
	 }
	 public static void WeatherOneDayDBprocess(String SQL) throws Exception{
		 System.out.println(SQL);
         int isok = InsertSql.insertable(SQL);
         if (isok==1){
         	System.out.println("success");
        
         }else if (isok==500){
         	System.out.println("PRIMARY");
         }else{
         	System.out.println("fail");
         }
	 }
	 public static void main(String[] args) throws Exception {
		 RequestWeatherOneDay();

		}

}
